

const Router = require('koa-router')
const router = new Router()
const moment = require('moment')

const {
    queryDeliveryOrderByPage
} = require('../../util/qplwmsApi')


router.get("/", async ctx => {
    return ctx.render('login')
})

/**
 * 每月执行入口
 */
router.get("/index", async ctx => {
    let dateString = moment().format('YYYY-MM-DD HH:mm:ss')
    let objs = {
        url: ctx.href,
        date: dateString
    }
    return ctx.render('index', { 'data': objs })
})


/**
 * 订单查询页面
 */
router.get("/query", async ctx => {
    return ctx.render('query')
})




/**
 * 订单查询
 */
router.post("/query", async ctx => {

    let res = {code:'9999'}

    let { sdate, edate, authorization } = ctx.request.body


    let data = {
        "apiVersion": null,
        "channel": "qplTms",
        "postData": {
            "createTimeStart": `${sdate} 00:00:00`,
            "createTimeEnd": `${edate} 23:59:59`,
            "driverName": null,
            "orderNo": null,
            "orderType": null,
            "carrierId": null,
            "shopName": null,
            "targetAddress": null,
            "pageIndex": 1,
            "pageSize": 5000,
            "whIds": [55939],
            "companyId": 1
        }
    }
    res = await queryDeliveryOrderByPage(res, data, authorization)
    return ctx.body = res
})




module.exports = router